package com.qidian.zl.paper.factory;

import com.qidian.zl.paper.dao.*;
import com.qidian.zl.paper.dao.impl.AnswerDAOImpl;
import com.qidian.zl.paper.dao.impl.FieldDAOImpl;
import com.qidian.zl.paper.dao.impl.PaperDAOImpl;
import com.qidian.zl.paper.dao.impl.AdminDAOImpl;

import java.util.HashMap;
import java.util.Map;

//创建工厂
public class DAOFactory {
    private static Map daoOjbs = new HashMap();
    /**
     * @Description:
     * @Param:
     * @return:
     * @Date:
     */
    public static PaperDAO getPaperDAO() {
        if (daoOjbs.containsKey("paperDAO")) {
            return (PaperDAO) daoOjbs.get("paperDAO");
        } else {
            PaperDAO paperDAO = new PaperDAOImpl();
            daoOjbs.put("paperDAO", paperDAO);
            return paperDAO;
        }
    }

    public static FieldDAO getFieldDAO() {
        if (daoOjbs.containsKey("fieldDAO")) {
            return (FieldDAO) daoOjbs.get("fieldDAO");
        } else {
            FieldDAO fieldDAO = new FieldDAOImpl();
            daoOjbs.put("fieldDAO", fieldDAO);
            return fieldDAO;
        }
    }

    public static SelectorDAO getSelectorDAO() {
        if (daoOjbs.containsKey("selectorDAO")) {
            return (SelectorDAO) daoOjbs.get("selectorDAO");
        } else {
            SelectorDAO selectorDAO = new SelectorDAOImpl();
            daoOjbs.put("selectorDAO", selectorDAO);
            return selectorDAO;
        }
    }

    public static AnswerDAO getAnswerDAO() {
        if (daoOjbs.containsKey("answerDAO")) {
            return (AnswerDAO) daoOjbs.get("answerDAO");
        }
        AnswerDAO answerDAO = new AnswerDAOImpl();
        daoOjbs.put("answerDAO", answerDAO);
        return answerDAO;
    }
    public static AdminDAO getUserDAO(){
        if (daoOjbs.containsKey("userDAO")){
            return (AdminDAO) daoOjbs.get("userDAO");
        }else {
            AdminDAO adminDAO =new AdminDAOImpl();
            daoOjbs.put("userDAO", adminDAO);
            return adminDAO;
        }
    }

}
